package com.itheima.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class MyAspect {

//    @Pointcut("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
//    public void pt(){};
    @Pointcut("@annotation(com.itheima.anno.MyLog)")
    public void pt(){};
//    @Before("pt()")
//    public void before(){
//        log.info("执行了before~~~");
//    }
//
//    @After("pt()")
//    public void after(){
//        log.info("执行了after~~~");
//    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pj) throws Throwable {  // 是一定要放入一个 ProceedingJoinPoint

        String className = pj.getTarget().getClass().getName();
        Signature signature = pj.getSignature();
        Object[] args = pj.getArgs();
        log.info("目标方法的类名 {}",className);
        log.info("目标方法的签名 {}",signature);
        log.info("目标方法的参数 {}",args);

//        log.info("around前~~~~");
        Object result = pj.proceed();
//        log.info("around后..");
        return result;
    }
//    @AfterReturning("pt()")
//    public void afterReturning(){
//        log.info("执行了AfterReturning~~~");
//    }
//
//    @AfterThrowing("pt()")
//    public void afterThrowing(){
//        log.info("执行了AfterThrowing~~~");
//    }


}
